package cn.line5.seam.cms.column;

import java.util.List;

import cn.line5.seam.annotations.AjaxRemote;
import cn.line5.seam.annotations.In;
import cn.line5.seam.annotations.Name;
import cn.line5.seam.annotations.Out;
import cn.line5.seam.annotations.Parameter;
import cn.line5.seam.db.PageResult;

@Name("columnRemote")
/**
 * <h1>LSEAM框架示例组件调用类</h1>
 * <br/>
 * 
 * @author Liu,yandong
 */
public class ColumnRemote {

	@In("columnService")
	// 注入业务层接口
	private ColumnService columnService;

	@Parameter
	// 参数
	private String id;
	
	@Out
	// 模块树的JS代码
	private String treeJs;

	@Parameter
	// 参数
	private String currentPage;

	@Parameter
	// 参数
	private ColumnVo vo;

	@Parameter
	// 参数
	private String[] deleteId;

	@Out
	// 输出
	private String returnMessage;

	@Out
	// 输出
	private List<ColumnVo> list;

	@Out
	// 输出
	private ColumnVo returnVo;

	@Out
	// 输出
	private PageResult<ColumnVo> pageResult;

	// 列表
	public void listColumn() {
		list = this.columnService.getList();
	}

	// 分页列表
	public void listPageColumn() {
		if(currentPage == null || currentPage.equals("")){
			currentPage = "1";
		}
		int page = Integer.parseInt(currentPage);
		pageResult = columnService.getPageList(page);
	}

	// 获取单个
	public void getColumn() {
		returnVo = this.columnService.getColumn(id);
	}

	// 增加栏目
	public void columnAdd() {
		ColumnVo columnVo = this.columnService.getColumnVo(vo);
		if(columnVo == null || columnVo.getColumnId().equals("")){
			//新增栏目
			this.columnService.saveColumn(vo);
			returnMessage = "";
		}else{
			//已经存在同名
			returnMessage = "";
		}
	}
	// 更新
	public void modifyColumn() {
		this.columnService.saveColumn(vo);
	}

	// 删除
	public void deleteColumn() {
		this.columnService.deleteColumn(deleteId);
	}


	/**
	 * 机构向上排序
	 */
	@AjaxRemote
	public Boolean upColumn(String parentColumnId ,String columnId) {
		return columnService.upColumn(parentColumnId,columnId);
	}

	/**
	 * 机构向下排序
	 */
	@AjaxRemote
	public Boolean downColumn(String parentColumnId ,String columnId) {
		return columnService.downColumn(parentColumnId,columnId);
	}

	/**
	 * 获取模块树
	 */
	public void columnTree() {
		treeJs = columnService.getColumnTreeJs();
	}	
}
